import type { MovePointOptions, MovePointResult } from "./useRectDrag";
import { getRotatePoint } from "/@/utils/draw";

export default function ({ rotatePoints, newPoint, rotate }: MovePointOptions): MovePointResult {
  const rotateCenterPoint = {
    x: newPoint.x + (rotatePoints[2].x - newPoint.x) / 2,
    y: newPoint.y + (rotatePoints[2].y - newPoint.y) / 2,
  };
  //拖动点的原始点
  const originalPoint = getRotatePoint(rotateCenterPoint, newPoint, 360 - rotate);
  //静态点的原始点
  const staticPoint = getRotatePoint(rotateCenterPoint, rotatePoints[2], 360 - rotate);
  let width = staticPoint.x - originalPoint.x;
  let height = originalPoint.y - staticPoint.y;
  if (width >= 0 && height >= 0) {
    return {
      newX: originalPoint.x,
      newY: staticPoint.y,
      newWidth: width,
      newHeight: height,
    };
  } else if (width >= 0 && height <= 0) {
    return {
      newX: originalPoint.x,
      newY: originalPoint.y,
      newHeight: -height,
      newWidth: width,
    };
  } else if (width <= 0 && height >= 0) {
    return {
      newWidth: -width,
      newX: staticPoint.x,
      newHeight: height,
      newY: staticPoint.y,
    };
  } else {
    return {
      newX: originalPoint.x - -width,
      newY: originalPoint.y,
      newWidth: -width,
      newHeight: -height,
    };
  }
}
